from django.db import models
from utils.basemodel import BaseModel
from user.models import UserModel
from course.models import CourseModel
# Create your models here.
class Coupon(models.Model):
    name=models.CharField(max_length=50,verbose_name='优惠券名称')
    price=models.IntegerField(verbose_name='优惠券金额')
    start_time=models.DateTimeField(verbose_name='优惠券开始时间')
    end_time=models.DateTimeField(verbose_name='优惠券结束时间')
    condition=models.CharField(max_length=100,default="",null=True)
    number=models.IntegerField(verbose_name="数量",default=10,null=True)
    type=models.CharField(verbose_name="类型",default="满减",max_length=100)
    class Meta:
        db_table='fgcoupon'
    def __str__(self):
        return self.name

class UserCoupon(BaseModel):
    user=models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name='用户')
    coupon=models.ForeignKey(Coupon,on_delete=models.CASCADE,verbose_name='优惠券')
    class Meta:
        db_table='fgusercoupon'
#订单模型
class OrderModel(BaseModel):
    user=models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name='用户')
    orderno=models.CharField(max_length=100,verbose_name='订单号')
    totalprice=models.DecimalField(verbose_name='订单总价',max_digits=10,decimal_places=2)
    payprice=models.DecimalField(verbose_name='支付金额',max_digits=10,decimal_places=2)
    status=models.IntegerField(verbose_name='订单状态',choices=((0,'待支付'),(1,'已支付'),(2,'已取消'),(3,'已完成')),default=0)
    score=models.IntegerField(verbose_name='积分',default=0)
    coupon=models.IntegerField(verbose_name="优惠券",null=True,blank=True)
    paytype=models.IntegerField(verbose_name='支付方式',choices=((0,'支付宝'),(1,'微信'),(2,'银行卡')),default=0)
    paytime=models.DateTimeField(verbose_name='支付时间',null=True,blank=True)
    payno=models.CharField(verbose_name='支付流水号',max_length=100,null=True,blank=True)
    class Meta:
        db_table='fgorder'
    def __str__(self):
        return self.orderno

#订单详情表
class OrderDetailModel(BaseModel):
    order=models.ForeignKey(OrderModel,on_delete=models.CASCADE,verbose_name='订单')
    course=models.ForeignKey(CourseModel,on_delete=models.CASCADE,verbose_name='课程')
    cname=models.CharField(verbose_name='课程名称',max_length=100)
    price=models.DecimalField(verbose_name='课程价格',max_digits=10,decimal_places=2)
    discount=models.DecimalField(verbose_name='折扣',max_digits=10,decimal_places=2)
    cover=models.CharField(verbose_name='课程封面',max_length=100)
    class Meta:
        db_table='fgorderdetail'
#用户购买课程
class MyCourseModel(BaseModel):
    user=models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name='用户')
    course=models.ForeignKey(CourseModel,on_delete=models.CASCADE,verbose_name='课程')
    cname = models.CharField(verbose_name='课程名称', max_length=100)
    price = models.DecimalField(verbose_name='课程价格', max_digits=10, decimal_places=2)
    discount = models.DecimalField(verbose_name='折扣', max_digits=10, decimal_places=2)
    cover = models.CharField(verbose_name='课程封面', max_length=100)

    class Meta:
        db_table = 'fgmycourse'








